
import {deepClone} from '@/utils'
export default{
    formatRoute(initMenus){
        this.menuLst = deepClone(initMenus)
        this.filterRoute(this.menuLst)
        let menus = [{
            path: '/',
            component:'/layout',
            redirect: '/dashboard',
            disabled: true,
            meta:{
                id:0,
                title: '首页',
                parentId: null,
            },
            children: this.menuLst
        }]
        return menus
    },
    menuLst:[],
    filterRoute(menus){
        menus.forEach(item => {
            if(item.children) this.filterRoute(item.children)
            if(item.redirect){
                item.redirect = item.redirect
            }
            item.path = item.url || '/blank'
            item.hidden = item.hidden || false
            item.meta = {
                id:item.id,
                title:item.name,
                icon:item.icon,
                parentId:item.parentId,
                parentName:item.parentName || '无',
                btnPermission:item.btnPermission || [],
                code:item.code,
                hidden:item.hidden || false
            }
            item.component = item.component || 'error-page/404'
            const delKeys = ['id','url','name','icon','parentId','parentName','btnPermission','childrenUrl','type','updateDate']
            delKeys.forEach(key => {
                delete item[key]
            })
            item.name = item.routeName || ''
            item.children = item.children     
            
        })
    }
}